<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    用户名<input type="text" class="user"> <br>
    密码<input type="text" class="pwd"> <br>
    手机号<input type="text" class="phone"> <br>
    邮箱<input type="text" class="email"> <br>
    <button>注册</button>



    <script>



        const oUser = document.querySelector('.user');
        const oPwd = document.querySelector('.pwd');
        const oPhone = document.querySelector('.phone');
        const oEmail = document.querySelector('.email');
        const oBtn = document.querySelector('button');


        oBtn.onclick = function () {
            // 手机号唯一      名称和内容   

            const username = oUser.value;
            const password = oPwd.value;
            const phone = oPhone.value;
            const email = oEmail.value;


            // const userObj = {
            //     username:username,
            //     password:password,
            //     email:email
            // }

            // 对象的简写
            const userObj = {
                username,
                password,
                email
            }

            console.log(userObj);

            // 判断手机号是否已被注册
            const res = localStorage.getItem('YYDS_' + phone);
            if (res) {
                alert('已被注册');
            } else {
                alert('注册成功');
                localStorage.setItem('YYDS_' + phone, JSON.stringify(userObj));
            }


        }




    </script>

</body>

</html>